package com.cdc.permission;

import android.content.Context;
import android.content.pm.PackageManager;

import androidx.core.content.ContextCompat;

public class PermissionsChecker{
    private final Context mContext;
    public PermissionsChecker(Context context) {
        mContext = context.getApplicationContext();
    }
    /**
     * 判断权限集合
     * @param permissions
     * @return true：有权限没有获取；false:权限都已被获取
     */
    public boolean lacksPermissions(String... permissions) {
        for (String permission : permissions) {
            if (lacksPermission(permission)) {
                return true;
            }
        }
        return false;
    }
    /**
     * 判断是否缺少权限
     * 即:某个权限没有获取到
     * @param permission
     * @return
     */
    private boolean lacksPermission(String permission) {
        return ContextCompat.checkSelfPermission(mContext, permission) ==
                PackageManager.PERMISSION_DENIED;
    }
}
